{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f6004e0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]\n",
    "# 1. copy()很重要\n",
    "# 思考，赋值是真正的复制么？ 赋值(=) <=> copy? 不等价  \n",
    "stu_id_matedata = stu_id\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)   #\\n转义字符，换行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "70538710",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "# 实验 1 赋值\n",
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]  \n",
    "stu_id_matedata = stu_id\n",
    "stu_id.pop(0)        #pop() 函数用于移除列表中的一个元素（默认最后一个元素），并且返回该元素的值。                    \n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9803dc9c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "# 实验2 copy()\n",
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]  \n",
    "stu_id_matedata = stu_id.copy()\n",
    "stu_id.pop(0)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e8aa87ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "# 实验3 切片实现复制\n",
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]  \n",
    "stu_id_matedata = stu_id[:]\n",
    "stu_id.pop(0)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "aa29035c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10001\n",
      "10001\n",
      "10001\n"
     ]
    }
   ],
   "source": [
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]\n",
    "# 思考，如何取出所有位置10001的index？\n",
    "for i in stu_id:\n",
    "    # 循环遍历stu_id的所有内容\n",
    "    if i == 10001:\n",
    "        # 判断如果元素为10001的时候,怎么取出索引值呢？\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9500eeea",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 10001\n",
      "5 10001\n",
      "8 10001\n",
      "我们想要pop10001的位置 [0, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 枚举:因为list其实不仅有values值，还有index索引值，但for循环主要循环遍历其值，不遍历索引\n",
    "# 因此，有了枚举的方法，同时遍历两者\n",
    "# enumerate()\n",
    "pop_values_list = []  # append方法经常用于新建列表\n",
    "for index,item in enumerate(stu_id):   #enumerate() 函数用于将一个可遍历的数据对象\n",
    "    if item == 10001:\n",
    "        print(index,item)\n",
    "        pop_values_list.append(index)  # append() 方法用于在列表末尾添加新的对象\n",
    "print(\"我们想要pop10001的位置\",pop_values_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "987e05b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列，同时列出数据和数据下标，一般用在 for 循环当中\n",
    "seasons = ['Spring', 'Summer', 'Fall', 'Winter']\n",
    "list(enumerate(seasons))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "d0391f1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(enumerate(seasons, start=1))       # 下标从 1 开始,而不是0了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "e9d0a1fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0, 'one')\n",
      "(1, 'two')\n",
      "(2, 'three')\n"
     ]
    }
   ],
   "source": [
    "seq = ['one', 'two', 'three']\n",
    "for i in enumerate(seq):\n",
    "    print (i)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
